package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.search.service.SearchService;
import io.lettuce.core.output.StringMatchResultOutput;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 上架专辑-导入索引库
     * @param albumId
     * @return
     */
    @Operation(summary = "上架专辑-导入索引库")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){

        searchService.upperAlbum(albumId);

        return Result.ok();
    }

    /**
     * 下架专辑-删除文档
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑-删除文档")
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /**
     * 为定时更新首页排行榜提供调用接口
     * @return
     */
    @Operation(summary = "为定时更新首页排行榜提供调用接口")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    /**
     * 获取排行榜单
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "获取排行榜单")
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> getRankingList (@PathVariable Long category1Id,@PathVariable String dimension){



        return Result.ok(searchService.getRankingList(category1Id,dimension));
    }


}

